import sqlite3

# sqlite3 封装 sql 执行函数
def executesql(db, sql):
	def dict_factory(cursor, row):
		d = {}
		for idx, col in enumerate(cursor.description):
			d[col[0]] = row[idx]
		return d
	conn = sqlite3.connect(db)
	conn.row_factory = dict_factory
	cur = conn.cursor()
	#print('\nsql: ', sql)
	cur.execute(sql)
	return cur.fetchall()

def executesql2(db, sql):
	try:
		conn = sqlite3.connect(db)
		cur = conn.cursor()
		#print('\nsql: ', sql)
		cur.execute(sql)
		conn.commit()
		return cur.fetchall()
	except Exception as e:
		conn.rollback()
		print('executesql err: ', str(e))
		return False
	finally:
		cur.close()
		conn.close()

if __name__ == '__main__':
	pass
